package cn.zmit.kuxi.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import cn.zmit.kuxi.R;

public class GridViewAddImageAdapter extends BaseAdapter {
	private Context mContext;

	private List<Bitmap> list = new ArrayList<Bitmap>();

	public void setList(List<Bitmap> list) {
		this.list = list;
		this.notifyDataSetChanged();
	}

	public GridViewAddImageAdapter() {
		super();
	}

	public GridViewAddImageAdapter(Context mContext, List<Bitmap> list) {
		super();
		this.mContext = mContext;
		this.list = list;  
	}

	@Override
	public int getCount() {

		return list.size();
	}

	@Override
	public Object getItem(int position) {

		return list.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.item_publish, null);
			holder = new ViewHolder();
			holder.iv = (ImageView) convertView
					.findViewById(R.id.item_grid_image);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.iv.setImageBitmap(list.get(position));
		return convertView;
	}

	class ViewHolder {
		ImageView iv;
	}

}
